package filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginFilter implements Filter{
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //禁止浏览器缓存所有动态页面
        response.setHeader("Pragma","no-cache");   //支持HTTP 1.0，告诉浏览器要不要缓存数据，如“no-cache”

        //使用no-cache的目的就是为了防止从缓存中获取过期的资源。
        // 使用no-cache的目的就是为了防止从缓存中获取过期的资源。
//        response.setHeader("Cache-Control","no-cache");
        response.setHeader("Cache-Control","no-store");
        response.setDateHeader("Expires", -1);   //告诉浏览器数据可以缓存多长时间，-1或0表示不缓存
        filterChain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
